home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Graphics / QuickDraw GX / GX->PostScript Sample / GXToPostScript / Internal Headers / DarnExceptions.h next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  16.7 KB  |  589 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        DarnExceptions.h
  3.  
  4.      Contains:    QuickDraw GX to PostScript conversion code.
  5.  
  6.      Version:    Technology:    Quickdraw GX 1.1.x
  7.       
  8.      Copyright:    © 1996-1997 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. #ifndef __EXCEPTIONS__
  12. #define __EXCEPTIONS__
  13.  
  14. #ifndef __TYPES__
  15. #include <Types.h>
  16. #endif
  17.  
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21.  
  22. #if PRAGMA_ALIGN_SUPPORTED
  23. #pragma options align=mac68k
  24. #endif
  25.  
  26. #if PRAGMA_IMPORT_SUPPORTED
  27. #pragma import on
  28. #endif
  29.  
  30. #define DEBUGOFF 0
  31. #define DEBUGWARN 1
  32. #define DEBUGMIN 2
  33. #define DEBUGON 3
  34. #define DEBUGFULL 4
  35. #define DEBUGCRITICAL 4
  36. #define DEBUGFEEDBACK 5
  37. #define DEBUGSYM 6
  38. #ifndef    DEBUGLEVEL
  39. #define DEBUGLEVEL DEBUGOFF
  40. #endif
  41.  
  42. #ifdef    debugfeedback
  43.     #undef    DEBUGLEVEL
  44.     #define DEBUGLEVEL DEBUGFEEDBACK
  45. #endif
  46.  
  47. #ifndef resumeLabel
  48. #define resumeLabel(exception) resume_##exception:
  49. #endif
  50. #define trace (StringPtr)"\p;dprintf;doTrace"
  51. #define notrace (StringPtr)"\p;dprintf"
  52. #define traceon ((DEBUGLEVEL > DEBUGWARN) && defined(TRACEON))
  53. #define debugon (DEBUGLEVEL > DEBUGWARN)
  54. #define __DEBUGSMALL ((DEBUGLEVEL == DEBUGMIN) ||     \
  55.     (DEBUGLEVEL == DEBUGSYM))
  56. #if    DEBUGLEVEL == DEBUGMIN
  57. #define __DebuggerBreak Debugger()
  58. #elif DEBUGLEVEL == DEBUGSYM
  59. #define __DebuggerBreak SysBreak()
  60. #endif
  61. #define QuoteExceptionString(x) #x
  62. /*********************************************************************
  63.  
  64. ROUTINE
  65.     void dprintf(traceOption, format, ...)
  66.  
  67. DESCRIPTION
  68.     dprintf is used like printf only the information is displayed in
  69.     MacsBug. traceOption is used to specify whether the execution
  70.     should continue after the break or not. format contains
  71.     two types of objects: ordinary characters, which are displayed in
  72.     Macsbug, and coversion specifications, each of which causes
  73.     conversion and printing of the next successive argument to dprintf.
  74.     Each conversion specification begins with a % and ends with a
  75.     conversion character. Between % and the conversion character there
  76.     may be, in order:
  77.     
  78.     •    Zero or more flag characters, which modify the meaning of the
  79.         conversion specification.
  80.     •    A number that specifies the minimum field width. The converted
  81.         argument will be printed in a field at least this wide. If
  82.         necessary it will be padded on the left (or right, if left
  83.         adjustment is called for) to make up the field width.
  84.     •    A period, which separates the field width from the precision.
  85.     •    A number, the precision, that specifies the maximum number of
  86.         characters to be printed from a string, or the number of digits
  87.         after the decimal point of a floatingpoint value, or the minimum
  88.         number of digits for an integer.
  89.     •    An h if the integer is to be printed as a short, or l if as
  90.         long (ignored since int is long), or L to specify that the
  91.         following e, E, f, g, or G conversion is a long double.
  92.     
  93.     Note: A field width or precision may be indicated by an * instead
  94.     of a digit string. In this case, an integer arg parameter supplies
  95.     the field width or precision. The arg parameter that is actually
  96.     converted is not fetched until the conversion letter is seen;
  97.     therefore, the arg paramters specifying field width or precision
  98.     must appear immediately before the arg parameter (if any) to be
  99.     converted.
  100.     
  101.     The flag characters are:
  102.     
  103.         -        The result of the conversion will be left justified
  104.                 within the field.
  105.         +        The result of a signed conversion always begins with a
  106.                 sign (+ or -).
  107.         space    If the first character of a signed conversion is not a
  108.                 sign, a space will be prefixed to the result. This implies
  109.                 that if the space and + flags both appear, the space flag
  110.                 will be ignored.
  111.         #        The value is to be converted to an alternate form. For c,
  112.                 d, s, and u conversions, the flag has no effect. For o
  113.                 conversions, it increases the precision to force the first
  114.                 digit of the result to be zero. For x, and X conversions,
  115.                 a nonzero result will have 0x or 0X prefixed to it. For
  116.                 e, E, f, g, and G conversions, the result will always
  117.                 contain a decimal point, even if no digits follow the
  118.                 point. For g and G conversion, trailing zeros in the
  119.                 fractional part will not be removed from the result.
  120.         0        The 0 flag pads the field with zeros on the left only;
  121.                 this applies to d, i, o, u, x, X, e, E, f, g, and G
  122.                 conversions. The leading zeros pad the field width, and
  123.                 no space padding is performed. If both the 0 and - flags
  124.                 appear, the 0 flag is ignored. If a precision is specified
  125.                 for d, i, o, u, x, and X conversions, the 0 flag is
  126.                 ignored.
  127.     
  128.     The standard conversions are:
  129.     
  130.         d,i        int            Decimal number.
  131.         o        int            Unsigned octal number (w/o a leading zero).
  132.         x,X        int            Unsigned hexadecimal number (w/o a leading 0x
  133.                                 or oX), using abcdef or ABCDEF for 10,…,15.
  134.         u        int            Unsigned decimal number.
  135.         c        int            Single character.
  136.         s        char*            C string.
  137.         f        double        [-]m.dddddd, where the number of d's is given
  138.                                 by the precision (default 6).
  139.         e,E        double        [-]m.dddddde±xx or [-]m.ddddddE±xx, where the
  140.                                 number of d's is given by the precision
  141.                                 (default 6).
  142.         g,G        double        Use %e or %E if the exponent is less than -4
  143.                                 or greater than or equal to the precision;
  144.                                 otherwise use %f. Trailing zeros and a
  145.                                 trailing decimal point are not printed.
  146.         p        void*        Pointer.
  147.         %                    No argument is converted; print a %.
  148.     
  149.     The supported MPW extensions are:
  150.     
  151.         P        StringPtr    Pascal string.
  152.     
  153.     Of the MPW printf convertion characters only "n" is not supported.
  154.     In addition to the standard characters, the following are defined:
  155.     
  156.         b        Boolean        Outputs either true or false.
  157.         j        Point            Used like the d option.
  158.         J        point*        Fixed point. Used like the f option.
  159.         F        Fixed            Used like the f option.
  160.         T        Fract            Used like the f option.
  161.         r        Rect*            Displays the rect with each piece seperated by
  162.                                 ", ". Used like the d option.
  163.         R        rectangle*    Similar to r but for fixed point rectangles.
  164.                                 Used like the f option.
  165.         M        mapping.        Displays the mapping seperated by ", " and
  166.                                 "\n". The third column is displayed as fract.
  167.                                 Used like the f option.
  168.     
  169.         
  170.     dprintf requires that the MacsBug dcmd dprintf is present.
  171.     
  172.     Characters used:     bcdefghij l nop rs u  x
  173.                                 EFG  J LM  P R T   X
  174.     Not used:            a         k m   q  t vw yz
  175.                             ABCD   HI K  NO Q S UVW YZ
  176.     
  177.     See the MPW C Reference for more information on printf.
  178.  
  179. Echo "                                                            ∂n∂
  180.     PRINT            OFF,NOHDR                                    ∂n∂
  181.     INCLUDE        'Traps.a'                                    ∂n∂
  182.     PRINT            ON                                                ∂n∂
  183.     PROC                                                            ∂n∂
  184.     MOVEA.L        SP,A0        ; Save the stackPtr            ∂n∂
  185.     _DebugStr                                                    ∂n∂
  186.     SUBQ            #4,SP        ; Fix the stack                ∂n∂
  187.     ENDPROC                                                        ∂n∂
  188.     END                                                            ∂n∂
  189. " | Asm -l
  190.  
  191. *********************************************************************/
  192.  
  193. #ifdef INSIDEOFGX
  194.     #if BUILDING_FOR_NUKERNEL && GENERATING68K
  195.  
  196.         extern pascal void NewDebugStr(ConstStr255Param damnMsg)
  197.          = {0x203C, 0xABFF, 0xABFF, 0x2078, 0x0948, 0x2050, 0x4E90};
  198.  
  199.         #undef DebugStr
  200.         #define DebugStr NewDebugStr
  201.         
  202.         extern void dprintf(StringPtr, char [], ...)
  203.          = {0x203C, 0xFEED, 0xABFF, 0x2278, 0x0948, 0x2251, 0x4E91};
  204.  
  205.     #else
  206.  
  207.         extern void dprintf(StringPtr, char [], ...)
  208.          THREEWORDINLINE(0x204F, 0xABFF, 0x594F);
  209.  
  210.     #endif
  211. #else
  212.  
  213.     void dprintf(StringPtr debuggerCommand, char formatString[], ...);
  214.  
  215. #endif
  216.  
  217. /*********************************************************************
  218.  
  219. ROUTINE
  220.     void* check_dprintf(assertion, traceOption, format, ...)
  221.  
  222. DESCRIPTION
  223.     If assertion is non-zero then assertion is returned. Otherwise the
  224.     dprintf is invoked and zero is returned.
  225.     
  226. Echo "                                                            ∂n∂
  227.     PRINT            OFF,NOHDR                                    ∂n∂
  228.     INCLUDE        'Traps.a'                                    ∂n∂
  229.     PRINT            ON                                                ∂n∂
  230.     PROC                                                            ∂n∂
  231.     MOVE.L        (SP)+,D0    ; Pop value into D0            ∂n∂
  232.     BNE.S            @1            ; If !0 then branch            ∂n∂
  233.     MOVEA.L        SP,A0        ; Save the stackPtr            ∂n∂
  234.     _DebugStr                                                    ∂n∂
  235.     SUBQ            #4,SP        ; Fix the stack                ∂n∂
  236.     CLR.L            D0            ; Result is zero                ∂n∂
  237. @1    SUBQ            #4,SP        ; Fix stack for pop            ∂n∂
  238.     ENDPROC                                                        ∂n∂
  239.     END                                                            ∂n∂
  240. " | Asm -l
  241.     
  242. *********************************************************************/
  243. #ifdef applec
  244. extern void *check_dprintf(void *, StringPtr, char [], ...)
  245.  SEVENWORDINLINE(0x201F, 0x6608, 0x204F, 0xABFF, 0x594F, 0x7000, 0x594F);
  246. #endif
  247. #ifdef applec
  248. extern void *checkpos_dprintf(void *, StringPtr, char [], ...)
  249.  SEVENWORDINLINE(0x201F, 0x6C08, 0x204F, 0xABFF, 0x594F, 0x7000, 0x594F);
  250. #endif
  251. #if    __DEBUGSMALL
  252. #define check(assertion)         \
  253.     do {                            \
  254.     if (assertion) ;                \
  255.     else __DebuggerBreak;            \
  256.     } while (false)
  257. #elif    DEBUGLEVEL == DEBUGON
  258. #define check(assertion)         \
  259.     do {                            \
  260.     if (assertion) ;                \
  261.     else {                            \
  262.     dprintf(notrace, "# Assertion \"%s\" Failed\n",    QuoteExceptionString(assertion)); \
  263.     }                                \
  264.     } while (false)
  265. #elif    DEBUGLEVEL == DEBUGFULL
  266. #define check(assertion)         \
  267.     do {                            \
  268.     if (assertion) ;                \
  269.     else {                            \
  270.     dprintf(notrace,    "# Assertion \"%s\" Failed\n"     \
  271.     "file %s; line %d\n",            \
  272.     QuoteExceptionString(assertion), __FILE__, __LINE__);     \
  273.     }                                \
  274.     } while (false)
  275. #else
  276. #define check(assertion)
  277. #endif
  278. #if    __DEBUGSMALL
  279. #define ncheck(assertion)         \
  280.     do {                            \
  281.     if (assertion) __DebuggerBreak;     \
  282.     } while (false)
  283. #elif    DEBUGLEVEL == DEBUGON
  284. #define ncheck(assertion)         \
  285.     do {                            \
  286.     void*    __privateAssertion    = (void*)(assertion);     \
  287.                                 \
  288.     if (__privateAssertion) {        \
  289.     dprintf(notrace, "# Assertion \"!(%s [= %d])\" Failed\n", \
  290.     QuoteExceptionString(assertion), __privateAssertion);     \
  291.     }                                \
  292.     } while (false)
  293. #elif    DEBUGLEVEL == DEBUGFULL
  294. #define ncheck(assertion)         \
  295.     do {                            \
  296.     void*    __privateAssertion    = (void*)(assertion);     \
  297.                                 \
  298.     if (__privateAssertion) {        \
  299.     dprintf(notrace,    "# Assertion \"!(%s [= %d])\" Failed\n" \
  300.     "file %s; line %d\n",            \
  301.     QuoteExceptionString(assertion), __privateAssertion, __FILE__, __LINE__);     \
  302.     }                                \
  303.     } while (false)
  304. #else
  305. #define ncheck(assertion)
  306. #endif
  307. #if    __DEBUGSMALL
  308. #define check_action(assertion, action)  \
  309.     do {                            \
  310.     if (assertion) ;                \
  311.     else {                            \
  312.     __DebuggerBreak;                \
  313.     { action }                        \
  314.     } while (false)
  315. #elif    DEBUGLEVEL == DEBUGON
  316. #define check_action(assertion, action)  \
  317.     do {                            \
  318.     if (assertion) ;                \
  319.     else {                            \
  320.     dprintf(notrace, "# Assertion \"%s\" Failed\n",    QuoteExceptionString(assertion)); \
  321.     { action }                        \
  322.     }                                \
  323.     } while (false)
  324. #elif    DEBUGLEVEL == DEBUGFULL
  325. #define check_action(assertion, action)  \
  326.     do {                            \
  327.     if (assertion) ;                \
  328.     else {                            \
  329.     dprintf(notrace,    "# Assertion \"%s\" Failed\n"     \
  330.     "file %s; line %d\n",            \
  331.     QuoteExceptionString(assertion), __FILE__, __LINE__);     \
  332.     { action }                        \
  333.     }                                \
  334.     } while (false)
  335. #else
  336. #define check_action(assertion, action)
  337. #endif
  338. #if    __DEBUGSMALL
  339. #define ncheck_action(assertion, action)  \
  340.     do {                            \
  341.     if (assertion) {                \
  342.     __DebuggerBreak;                \
  343.     { action }                        \
  344.     }                                \
  345.     } while (false)
  346. #elif    DEBUGLEVEL == DEBUGON
  347. #define ncheck_action(assertion, action)  \
  348.     do {                            \
  349.     void*    __privateAssertion    = (void*)(assertion);     \
  350.                                 \
  351.     if (__privateAssertion) {        \
  352.     dprintf(notrace, "# Assertion \"!(%s [= %d])\" Failed\n", \
  353.     QuoteExceptionString(assertion), __privateAssertion);     \
  354.     { action }                        \
  355.     }                                \
  356.     } while (false)
  357. #elif DEBUGLEVEL == DEBUGFULL
  358. #define ncheck_action(assertion, action)  \
  359.     do {                            \
  360.     void*    __privateAssertion    = (void*)(assertion);     \
  361.                                 \
  362.     if (__privateAssertion) {        \
  363.     dprintf(notrace,    "# Assertion \"!(%s [= %d])\" Failed\n" \
  364.     "file %s; line %d\n",            \
  365.     QuoteExceptionString(assertion), __privateAssertion, __FILE__, __LINE__);     \
  366.     { action }                        \
  367.     }                                \
  368.     } while (false)
  369. #else
  370. #define ncheck_action(assertion, action)
  371. #endif
  372. #if    __DEBUGSMALL
  373. #define require(assertion, exception)  \
  374.     do {                            \
  375.     if (assertion) ;                \
  376.     else {                            \
  377.     __DebuggerBreak;                \
  378.     goto exception;                \
  379.     resumeLabel(exception);        \
  380.     }                                \
  381.     } while (false)
  382. #elif    DEBUGLEVEL == DEBUGON
  383. #define require(assertion, exception)  \
  384.     do {                            \
  385.     if (assertion) ;                \
  386.     else {                            \
  387.     dprintf(notrace, "# Assertion \"%s\" Failed\n"     \
  388.     "# Exception \"%s\" Raised\n",     \
  389.     QuoteExceptionString(assertion),  \
  390.     QuoteExceptionString(exception));     \
  391.     goto exception;                \
  392.     resumeLabel(exception);        \
  393.     }                                \
  394.     } while (false)
  395. #elif DEBUGLEVEL == DEBUGFULL
  396. #define require(assertion, exception)  \
  397.     do {                            \
  398.     if (assertion) ;                \
  399.     else {                            \
  400.     dprintf(notrace, "# Assertion \"%s\" Failed\n"     \
  401.     "# Exception \"%s\" Raised\n"     \
  402.     "file %s; line %d\n",            \
  403.     QuoteExceptionString(assertion),  \
  404.     QuoteExceptionString(exception),     \
  405.     __FILE__, __LINE__);            \
  406.     goto exception;                \
  407.     resumeLabel(exception);        \
  408.     }                                \
  409.     } while (false)
  410. #else
  411. #define require(assertion, exception)  \
  412.     do {                            \
  413.     if (assertion) ;                \
  414.     else {                            \
  415.     goto exception;                \
  416.     resumeLabel(exception);        \
  417.     }                                \
  418.     } while (false)
  419. #endif
  420. #if    __DEBUGSMALL
  421. #define nrequire(assertion, exception)  \
  422.     do {                            \
  423.     if (assertion) {                \
  424.     DebugStr();                    \
  425.     goto exception;                \
  426.     resumeLabel(exception);        \
  427.     }                                \
  428.     } while (false)
  429. #elif DEBUGLEVEL == DEBUGON
  430. #define nrequire(assertion, exception)  \
  431.     do {                            \
  432.     void*    __privateAssertion    = (void*)(assertion);     \
  433.                                 \
  434.     if (__privateAssertion) {        \
  435.     dprintf(notrace, "# Assertion \"!(%s [= %d])\" Failed\n"     \
  436.     "# Exception \"%s\" Raised\n",     \
  437.     QuoteExceptionString(assertion), __privateAssertion,  \
  438.     QuoteExceptionString(exception));     \
  439.     goto exception;                \
  440.     resumeLabel(exception);        \
  441.     }                                \
  442.     } while (false)
  443. #elif DEBUGLEVEL == DEBUGFULL
  444. #define nrequire(assertion, exception)  \
  445.     do {                            \
  446.     void*    __privateAssertion    = (void*)(assertion);     \
  447.                                 \
  448.     if (__privateAssertion) {        \
  449.     dprintf(notrace,    "# Assertion \"!(%s [= %d])\" Failed\n"     \
  450.     "# Exception \"%s\" Raised\n"     \
  451.     "file %s; line %d\n",            \
  452.     QuoteExceptionString(assertion),     \
  453.     __privateAssertion,         \
  454.     QuoteExceptionString(exception), __FILE__,     \
  455.     __LINE__);                        \
  456.     goto exception;                \
  457.     resumeLabel(exception);        \
  458.     }                                \
  459.     } while (false)
  460. #else
  461. #define nrequire(assertion, exception)  \
  462.     do {                            \
  463.     if (assertion) {                \
  464.     goto exception;                \
  465.     resumeLabel(exception);        \
  466.     }                                \
  467.     } while (false)
  468. #endif
  469. #if    __DEBUGSMALL
  470. #define require_action(assertion, exception, action)  \
  471.     do {                            \
  472.     if (assertion) ;                \
  473.     else {                            \
  474.     __DebuggerBreak;                \
  475.     { action }                        \
  476.     goto exception;                \
  477.     resumeLabel(exception);        \
  478.     }                                \
  479.     } while (false)
  480. #elif    DEBUGLEVEL == DEBUGON
  481. #define require_action(assertion, exception, action)  \
  482.     do {                            \
  483.     if (assertion) ;                \
  484.     else {                            \
  485.     dprintf(notrace,    "# Assertion \"%s\" Failed\n"     \
  486.     "# Exception \"%s\" Raised\n",     \
  487.     QuoteExceptionString(assertion), QuoteExceptionString(exception));     \
  488.     { action }                        \
  489.     goto exception;                \
  490.     resumeLabel(exception);        \
  491.     }                                \
  492.     } while (false)
  493. #elif DEBUGLEVEL == DEBUGFULL
  494. #define require_action(assertion, exception, action)  \
  495.     do {                            \
  496.     if (assertion) ;                \
  497.     else {                            \
  498.     dprintf(notrace,    "# Assertion \"%s\" Failed\n"     \
  499.     "# Exception \"%s\" Raised\n"     \
  500.     "file %s; line %d\n",            \
  501.     QuoteExceptionString(assertion),  \
  502.     QuoteExceptionString(exception), __FILE__, __LINE__);     \
  503.     { action }                        \
  504.     goto exception;                \
  505.     resumeLabel(exception);        \
  506.     }                                \
  507.     } while (false)
  508. #else
  509. #define require_action(assertion, exception, action)  \
  510.     do {                            \
  511.     if (assertion) ;                \
  512.     else {                            \
  513.     { action }                        \
  514.     goto exception;                \
  515.     resumeLabel(exception);        \
  516.     }                                \
  517.     } while (false)
  518. #endif
  519. #if    __DEBUGSMALL
  520. #define nrequire_action(assertion, exception, action)  \
  521.     do {                            \
  522.     if (assertion) {                \
  523.     __DebuggerBreak;                \
  524.     { action }                        \
  525.     goto exception;                \
  526.     resumeLabel(exception);        \
  527.     }                                \
  528.     } while (false)
  529. #elif DEBUGLEVEL == DEBUGON
  530. #define nrequire_action(assertion, exception, action)  \
  531.     do {                            \
  532.     void*    __privateAssertion    = (void*)(assertion);     \
  533.                                 \
  534.     if (__privateAssertion) {        \
  535.     dprintf(notrace,    "# Assertion \"!(%s [= %d])\" Failed\n"     \
  536.     "# Exception \"%s\" Raised\n",     \
  537.     QuoteExceptionString(assertion), __privateAssertion,  \
  538.     QuoteExceptionString(exception));     \
  539.     { action }                        \
  540.     goto exception;                \
  541.     resumeLabel(exception);        \
  542.     }                                \
  543.     } while (false)
  544. #elif DEBUGLEVEL == DEBUGFULL
  545. #define nrequire_action(assertion, exception, action)  \
  546.     do {                            \
  547.     void*    __privateAssertion    = (void*)(assertion);     \
  548.                                 \
  549.     if (__privateAssertion) {        \
  550.     dprintf(notrace,    "# Assertion \"!(%s [= %d])\" Failed\n"     \
  551.     "# Exception \"%s\" Raised\n"     \
  552.     "file %s; line %d\n",            \
  553.     QuoteExceptionString(assertion), __privateAssertion,  \
  554.     QuoteExceptionString(exception), __FILE__,     \
  555.     __LINE__);                        \
  556.     { action }                        \
  557.     goto exception;                \
  558.     resumeLabel(exception);        \
  559.     }                                \
  560.     } while (false)
  561. #else
  562. #define nrequire_action(assertion, exception, action)  \
  563.     do {                            \
  564.     if (assertion) {                \
  565.     { action }                        \
  566.     goto exception;                \
  567.     resumeLabel(exception);        \
  568.     }                                \
  569.     } while (false)
  570. #endif
  571. #define resume(exception)         \
  572.     do {                            \
  573.     goto resume_##exception;        \
  574.     } while (false)
  575.  
  576. #if PRAGMA_IMPORT_SUPPORTED
  577. #pragma import off
  578. #endif
  579.  
  580. #if PRAGMA_ALIGN_SUPPORTED
  581. #pragma options align=reset
  582. #endif
  583.  
  584. #ifdef __cplusplus
  585. }
  586. #endif
  587.  
  588. #endif /* __EXCEPTIONS__ */
  589.